package cn.sharp.bbs.service.impl;

import cn.sharp.bbs.dao.gen.UserMapper;
import cn.sharp.bbs.entity.BO.CurrentUser;
import cn.sharp.bbs.entity.DO.User;
import cn.sharp.bbs.service.CommonService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional
@Service
public class CommonServiceImpl implements CommonService {
    @Resource
    UserMapper userMapper;

    /**
     * 依据u_id获取用户实体
     * @param u_id 用户id
     * @return 返回用户实体 CurrentUser
     */
    @Override
    public CurrentUser getCurrentUser(Long u_id) {
        User user = userMapper.selectByPrimaryKey(u_id);
        return new CurrentUser(user.getId(), user.getNum(), user.getName(), user.getAvatar());
    }
}
